| Total Complexity | 1 |
| Total Lines | 20 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import * as pathlib from 'path'; |
||
| 10 | |||
| 11 | @Injectable() |
||
| 12 | export class DocxAdapter implements IDocxService { |
||
| 13 | constructor( |
||
| 14 | @Inject(DOCX_OPTIONS_TOKEN) |
||
| 15 | private readonly options: DocxOptions |
||
| 16 | ) {} |
||
| 17 | |||
| 18 | public async toBuffer( |
||
| 19 | name: string, |
||
| 20 | locals: Record<string, any> = {} |
||
| 21 | ): Promise<Buffer> { |
||
| 22 | // Dynamically load docx generator function from: |
||
| 23 | // {root}/{name}/docx.ts |
||
| 24 | const path = pathlib.join(this.options.root, name, 'docx'); |
||
| 25 | const mod: any = await import(path); |
||
| 26 | const fn: DocxFunction = mod.fn; |
||
| 27 | |||
| 28 | const doc = fn(locals); |
||
| 29 | return Packer.toBuffer(doc); |
||
| 30 | } |
||
| 32 |